package controller;



import gui.catalogues.telephones.dto.TelephoneDTO;

import java.sql.SQLException;
import java.util.List;

import model.DatabaseCommons;
import model.Telephone;
import model.TelephoneDAO;

public class TelephoneController {
	// DummyDB db = new DummyDB();
//	PersonDAO db = new PersonDAO();
	TelephoneDAO db = new TelephoneDAO();
	DatabaseCommons dbc = new DatabaseCommons();

	public List<Telephone> getElementList() {
		return db.getElements();
	}

	public void addElement(TelephoneDTO e) {
		Telephone element = new Telephone(e.getId(), e.getIdType(), e.getDesc());
		
		db.addElement(element);
	}

	public void removeElement(int index) {
		db.removeElement(index);
	}
	
	public void connectToDB() throws SQLException {
		dbc.h2Connect();
	}

	public void saveToDB() throws SQLException {
		db.saveToDB();
	}

	public void loadFromDB() throws SQLException {
		db.loadFromDB();
	}

	public void disconnectFromDB() throws SQLException {
		dbc.disconnect();
	}
	
	public void addTelephone(int idTelephoneType, int idPerson, String telephone) {
		try {
			db.addTelephone(idTelephoneType, idPerson, telephone);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
